{% load static %}
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>{{ proj.name }}项目</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href={% static "css/font.css" %}>
    <link rel="stylesheet" href={% static "css/xadmin.css" %}>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src={% static "lib/layui/layui.js" %} charset="utf-8"></script>
    <script type="text/javascript" src={% static "js/xadmin.js" %}></script>

    <link href="{% static "css/base.css" %}" rel="stylesheet">
    <link href="{% static "css/report.css" %}" rel="stylesheet">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body class="layui-anim layui-anim-up">
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="/">首页</a>
        <a href="#">安全扫描</a>
          <a href="#">被动注入</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md6 x-so" method="get" action="">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="domain" id="domain" placeholder="域名" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-input-inline">

                    <select name="status" lay-filter="status">
                        <option value="0" selected=""></option>
                        <option value="1">运行中</option>
                        <option value="2">结束</option>
                        <option value="3">显示漏洞</option>

                    </select>

                </div>
                <button class="layui-btn" lay-submit="search" lay-filter="search"><i class="layui-icon"></i></button>
            </div>


        </form>

        <button class="layui-btn layui-btn" onclick="start_api()">启动SQLMAP-API</button>
        <button class="layui-btn layui-btn" onclick="stop_api()">停止SQLMAP-API</button>
        <button class="layui-btn layui-btn" onclick="update_auth()">更新认证</button>
        <button class="layui-btn layui-btn" onclick="start_sqlmap()">注入</button>
        <span class="x-right"
              style="line-height:40px">接口状态:{{ run_status }}，任务数:{{ t }}
        </span>

    </div>
    <table class="layui-hide" id="sqlmap" lay-filter="sqlmap"></table>


</div>


<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="check_nlog">查看实时日志</a>
    <a class="layui-btn layui-btn-xs" lay-event="check_log">查看完整日志</a>
    <a class="layui-btn layui-btn-xs" lay-event="check_data">查看数据包</a>
    <a class="layui-btn layui-btn-xs" lay-event="restart">重新注入</a>
</script>


<script>
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;

        table.render({
            elem: '#sqlmap'
            , url: '{% url "get_inject_data" %}?domain={{ domain }}&status={{ status }}'
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'id', title: 'ID', width: 80, fixed: 'left', sort: true}
                , {field: 'taskid', title: 'taskid', width: 170, fixed: 'left', sort: true}

                , {field: 'run_status', title: '运行状态', width: 120, edit: 'text'}
                , {field: 'parameter', title: '漏洞参数', width: 120, edit: 'text'}
                , {field: 'host', title: 'host', width: 160, edit: 'text'}
                , {field: 'log_status', title: '日志状态', width: 120, edit: 'text'}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 400}


            ]]
            , page: true
        });


        //监听行工具事件
        table.on('tool(sqlmap)', function (obj) {

            var taskid = obj.data.taskid;


            if (obj.event === 'check_log') {
                layer.open({
                    type: 2
                    , title: '查看日志'
                    , content: "{% url "check_log" %}?taskid=" + taskid
                    , maxmin: true
                    , area: ['1000px', '500px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                        submit.click();
                    }
                });
            } else if (obj.event === 'check_data') {
                layer.open({
                    type: 2
                    , title: '查看数据包'
                    , content: "{% url "check_data" %}?taskid=" + taskid
                    , maxmin: true
                    , area: ['1000px', '500px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                        submit.click();
                    }
                });
            } else if (obj.event === 'check_nlog') {
                layer.open({
                    type: 2
                    , title: '查看实时日志'
                    , content: "{% url "check_nlog" %}?taskid=" + taskid
                    , maxmin: true
                    , area: ['1000px', '500px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                        submit.click();
                    }
                });
            } else if (obj.event === 'restart') {
                layer.confirm('是否要重新注入？', function (index) {
                    $.ajax(
                        {
                            url: "{% url "resart_injection_api" %}?taskid="+taskid,
                            method: "GET",

                        }
                    );
                    layer.close(index);
                    layer.alert('重新注入成功，请稍等~~~', {
                        time: 2000,
                        end: function () {
                            location.href = ""
                        }
                    })

                });

            }
        });
    });
</script>


<script>

    function start_api() {
        layer.confirm('确认要启动SQLMAP-API？', function (index) {
            $.ajax(
                {
                    url: "{% url "start_sqlmap_api" %}",
                    method: "GET",

                }
            );
            layer.close(index);
            layer.alert('启动成功', {
                time: 2000,
                end: function () {
                    location.href = ""
                }
            })

        });
    }

    function stop_api() {
        layer.confirm('确认要关闭SQLMAP-API？', function (index) {
            $.ajax(
                {
                    url: "{% url "stop_sqlmap_api" %}",
                    method: "GET",

                }
            );
            layer.close(index);
            layer.alert('停止成功', {
                time: 2000,
                end: function () {
                    location.href = ""
                }
            })

        });
    }

    function update_auth() {
        layer.open({
            type: 2
            , title: '更新验证'
            , content: "{% url "update_auth" %}"
            , maxmin: true
            , area: ['500px', '500px']

        });
    }


    function start_sqlmap() {
        layer.open({
            type: 2
            , title: '注入'
            , content: "{% url "start_sqlmap" %}"
            , maxmin: true
            , area: ['500px', '500px']

        });
    }


</script>


</body>
</html>


